package com.shijiwei.lifthelper.utils;

import java.math.BigDecimal;

/**
 * Created by sjw on 2015/12/18.
 */
public class DistanceUtils {
    public static String format(double value, int scale, int roundMode) {
        String distance = "";
        if (value >= 1000){
            value = value / 1000;
            BigDecimal bigDecimal = new BigDecimal(value);
            bigDecimal = bigDecimal.setScale(scale, roundMode);
            double result = bigDecimal.doubleValue();
            bigDecimal = null;
            distance = "距离：" + result + "公里";
        }else {
            BigDecimal bigDecimal = new BigDecimal(value);
            bigDecimal = bigDecimal.setScale(scale, roundMode);
            double result = bigDecimal.doubleValue();
            bigDecimal = null;
            distance = "距离：" + result + "米";
        }

        return distance;
    }
}
